package com.snack.common.utils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class DateFormatUtils
{
  public static final Map<String, DateFormat> FORMAT_CACHE = new HashMap<String, DateFormat>();


  public static String format(long millis, String pattern)
  {
    return format(new Date(millis), pattern);
  }

  public static String format(Date date, String pattern)
  {
	  DateFormat format = FORMAT_CACHE.get(pattern);
	  if(format == null){
		  synchronized (FORMAT_CACHE) {
			  format = new SimpleDateFormat(pattern);
			  FORMAT_CACHE.put(pattern, format);
		}
	  }
	  return format.format(date);
  }
}
